package org.brain.bean;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import org.brain.dbo.DBOperate;
import org.brain.pojos.Commentinfo;
import org.brain.pojos.Document;
import org.brain.pojos.User;
import org.brain.tool.ToolBean;

@ManagedBean(name="commentBean")
@SessionScoped
public class CommentBean {
	private List<Commentinfo> comList = new ArrayList();
	private Integer commentid;
	private Document document;
	private String commentcontent;
	int row = 0;
	
	private Date date;
	private String commentuser;
	private Commentinfo com= new Commentinfo();
	
	public void initCommentbean(){
		commentid = Integer.parseInt(ToolBean.getRequestParameter("commentid"));
        comList = DBOperate.search("Commentinfo where comdocumentid="+commentid+"");
        row=comList.size();
	}
	
	public void initaddComment(){
		User user;
		user = ToolBean.getUserSession();
		commentuser=user.getUsername();
		boolean flag=false;
		commentid = Integer.parseInt(ToolBean.getRequestParameter("commentid"));
		com.setComdocumentid(commentid);
		com.setCommentcontent(commentcontent);
		com.setCommenttime((Timestamp) date);
		com.setCommentuser(commentuser);
		flag = DBOperate.save(com);
	}
	public int getRow() {
		return row;
	}
	public void setRow(int row) {
		this.row = row;
	}
	public Integer getCommentid() {
		commentid = Integer.parseInt(ToolBean.getRequestParameter("commentid"));
		return commentid;
	}
	public void setCommentid(Integer commentid) {
		this.commentid = commentid;
	}
	public Document getDocument() {
		return document;
	}
	public void setDocument(Document document) {
		this.document = document;
	}
	public String getCommentcontent() {
		return commentcontent;
	}
	public void setCommentcontent(String commentcontent) {
		this.commentcontent = commentcontent;
	}
	public void setComList(List<Commentinfo> comList) {
		this.comList = comList;
	}
	public List<Commentinfo> getComList() {
		initCommentbean();
		return comList;
	}

}
	


